package org.csmzxy.class233;

public class Account {
    //账户编号
    private String cardId;
    //账户余额
    private double money;

    public Account(String cardId, double money) {
        this.cardId = cardId;
        this.money = money;
    }

    public String getCardId() {
        return cardId;
    }

    public void setCardId(String cardId) {
        this.cardId = cardId;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    //取钱方法
    public void drawMoney(double money) {
        //获取取钱的用户名,即线程的名字
        String name = Thread.currentThread().getName();
        synchronized (this) {
            //判断账户余额是否足够
            if (this.money >= money) {
                //取钱提示
                System.out.println(name + "来取钱成功，取出:" + money);
                //更新余额
                this.money -= money;
                System.out.println(name + "取钱后剩余:" + this.money);
            } else {
                //余额不足
                System.out.println(name + "来取钱,余额不足!");
            }
        }
    }
}